# -*- coding: utf-8 -*-
"""
Created on Fri Dec 31 10:02:23 2021

@author: Administrator
"""

import pandas as pd
import numpy as np
import os
import re

path = r'C:\Users\Administrator\Desktop\5G基站代码查询'
os.chdir(path)

code = 'AC4511000'
code = 'AC376B002'
def code2cellid(code):
    if len(code) == 9:
        cellid = str(int('0x'+ code[:-3] ,16)) + '_' + str(int('0x'+ code[-3:] ,16))
    else:
        cellid = int('0x'+ code,16)
    return cellid


fourG = 'LTE全量工参_2021-12-31.xlsx'
fiveG = '5G全量工参_2021-12-31.xlsx'
df4 = pd.read_excel(fourG)
df4 = df4[['CELLID','站名']]
df5 = pd.read_excel(fiveG)
df5 = df5[['CELL','CELLNAME']]

df4 = df4.set_index('CELLID',inplace = False)
df5 = df5.set_index('CELL',inplace = False)

fourG_dict = df4['站名'].to_dict()
fiveG_dict = df5['CELLNAME'].to_dict()
fourG_dict.update(fiveG_dict)

string1 = '''
请帮云南工业技师学院查询233E3836  ,   04594D47   ,  0459E665  ,  23C8FF5E ,  045B2332, 233E3806 基站编码的具体位置是否属于校园内基站,谢谢!
请帮云南工业技师学院查询045B1266  ,   045B2333   ,  045B1459三个基站编码的具体位置是否属于校园内基站,谢谢!
冯师，请帮忙查一下这二个基站是不是我们医专的。AC4511000   AC376B002
冯师，麻烦帮我查下这几个基站是那里的，又有学生投诉费用用超。基站编码：045C354B   0459D6C6    04599D5A   006F5C86
'''


p1 = r'((\d|[ABCDEF]){8,9})'
partten1 = re.compile(p1)
codes = re.findall(partten1,string1)
codes = [x[0] for x in codes]

cellids = [code2cellid(x) for x in codes]
cell_names = [fourG_dict.setdefault(x,'未查到') for x in cellids]

res_dict = {k:v for k,v in zip(codes,cell_names)}

for code,name in res_dict.items():
    print(code,' : ',name)
